package com.ftg.learn.chapter03.business.ui;

import com.ftg.learn.chapter03.business.service.UserService;
import com.ftg.learn.chapter03.business.util.Info;

import java.util.Scanner;

/**
 * 运行
 *
 * @author 布衣
 */
public class Running {

    public static void main(String[] args) {
        System.out.println("-==========--");
        System.out.println("-===Welcome====--");
        System.out.println("-==========--");
        UserService userService = new UserService();
        while(true){
            System.out.println("请选择您的操作 1 [登陆功能] 2 [注册功能] 0 【退出系统】");

            Scanner menu = new Scanner(System.in);

            int opType = menu.nextInt();

            if(opType == 0){
                break;
            }

            switch (opType) {
                case 1:
                    System.out.println("欢迎来到登陆页面");
                    System.out.println("请输入您的用户名，【只能为数字字母6-8位组成】");
                    String loginUser = menu.next();
                    System.out.println("请输入您的密码，【只能为数字字母6-8位组成】");
                    String loginPass = menu.next();

                    System.out.println("验证码为: 1234");
                    String capath = menu.next();

                    // code : 200 | 500 msg : 信息

                    Info login = userService.login(loginUser,loginPass,capath);
                    if(login.code == 200){
                        System.out.println(login.msg);
                        break;
                    }else{
                        System.out.println(login.msg);
                        break;
                    }
                case 2:
                    System.out.println("欢迎来到注册页面");
                    System.out.println("请输入您的用户名，【只能为数字字母6-8位组成】");
                    String username = menu.next();

                    System.out.println("请输入您的密码，【只能为数字字母6-8位组成】");
                    String password = menu.next();

                    System.out.println("请输入您的确认密码，【只能为数字字母6-8位组成】");
                    String confirmPassword = menu.next();

                    //要有一个业务判定,

                    boolean ist = userService.register(username,password,confirmPassword);
                    if(ist){
                        System.out.println("恭喜您注册成功");
                    }
                    break;
                default:
                    System.out.println("操作失误，请重新输入");
            }

            System.out.println();
        }



    }

}
